const data = [
    { id: 1, name: "集团" },
    { id: 2, name: "公司" },
    {
        id: 3, name: "部门", children: [
            {id:31,name:"开发部门"},
            {id:32,name:"市场部门"}
        ]
    },
]

let array = []
function deep(values){
    for (const item of values) {
        if(!item.children){
            array.push(item)
        }else{
            // array.push(item)
            deep(item.children)
        }
    }
}
deep(data)
console.log(array);




